import socket


def main():
    # 创建一个tcp套接字
    tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # 连接服务器地址
    server_addr = ("127.0.0.1", 8080)
    # 创建连接
    tcp_socket.connect(server_addr)

    while True:
        # 发送数据/接受数据
        send_data = input("请输入要发送的数据")
        tcp_socket.send(send_data.encode("utf-8"))
        recv = tcp_socket.recv(1024)
        print(recv.decode("utf-8"))


# 程序入口
if __name__ == "__main__":
    main()
